home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / mfb / maskbits.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-15  |  17.9 KB  |  593 lines

  1. /* Combined Purdue/PurduePlus patches, level 2.1, 1/24/89 */
  2. /***********************************************************
  3. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  4. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, and distribute this software and its
  9. documentation for any purpose and without fee is hereby granted,
  10. provided that the above copyright notice appear in all copies and that
  11. both that copyright notice and this permission notice appear in
  12. supporting documentation, and that the names of Digital or MIT not be
  13. used in advertising or publicity pertaining to distribution of the
  14. software without specific, written prior permission.
  15.  
  16. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  18. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  19. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22. SOFTWARE.
  23.  
  24. ******************************************************************/
  25. /* $XConsortium: maskbits.h,v 1.21 89/11/13 09:36:56 rws Exp $ */
  26. #include "X.h"
  27. #include "Xmd.h"
  28. #include "servermd.h"
  29.  
  30. extern int starttab[];
  31. extern int endtab[];
  32. extern unsigned partmasks[32][32];
  33. extern int rmask[];
  34. extern int mask[];
  35.  
  36.  
  37. /* the following notes use the following conventions:
  38. SCREEN LEFT                SCREEN RIGHT
  39. in this file and maskbits.c, left and right refer to screen coordinates,
  40. NOT bit numbering in registers.
  41.  
  42. starttab[n]
  43.     bits[0,n-1] = 0    bits[n,31] = 1
  44. endtab[n] =
  45.     bits[0,n-1] = 1    bits[n,31] = 0
  46.  
  47. startpartial[], endpartial[]
  48.     these are used as accelerators for doing putbits and masking out
  49. bits that are all contained between longword boudaries.  the extra
  50. 256 bytes of data seems a small price to pay -- code is smaller,
  51. and narrow things (e.g. window borders) go faster.
  52.  
  53. the names may seem misleading; they are derived not from which end
  54. of the word the bits are turned on, but at which end of a scanline
  55. the table tends to be used.
  56.  
  57. look at the tables and macros to understand boundary conditions.
  58. (careful readers will note that starttab[n] = ~endtab[n] for n != 0)
  59.  
  60. -----------------------------------------------------------------------
  61. these two macros depend on the screen's bit ordering.
  62. in both of them x is a screen position.  they are used to
  63. combine bits collected from multiple longwords into a
  64. single destination longword, and to unpack a single
  65. source longword into multiple destinations.
  66.  
  67. SCRLEFT(dst, x)
  68.     takes dst[x, 32] and moves them to dst[0, 32-x]
  69.     the contents of the rest of dst are 0 ONLY IF
  70.     dst is UNSIGNED.
  71.     this is a right shift on LSBFirst (forward-thinking)
  72.     machines like the VAX, and left shift on MSBFirst
  73.     (backwards) machines like the 680x0 and pc/rt.
  74.  
  75. SCRRIGHT(dst, x)
  76.     takes dst[0,x] and moves them to dst[32-x, 32]
  77.     the contents of the rest of dst are 0 ONLY IF
  78.     dst is UNSIGNED.
  79.     this is a left shift on LSBFirst, right shift
  80.     on MSBFirst.
  81.  
  82.  
  83. the remaining macros are cpu-independent; all bit order dependencies
  84. are built into the tables and the two macros above.
  85.  
  86. maskbits(x, w, startmask, endmask, nlw)
  87.     for a span of width w starting at position x, returns
  88. a mask for ragged bits at start, mask for ragged bits at end,
  89. and the number of whole longwords between the ends.
  90.  
  91. maskpartialbits(x, w, mask)
  92.     works like maskbits(), except all the bits are in the
  93.     same longword (i.e. (x&0x1f + w) <= 32)
  94.  
  95. mask32bits(x, w, startmask, endmask, nlw)
  96.     as maskbits, but does not calculate nlw.  it is used by
  97.     mfbGlyphBlt to put down glyphs <= 32 bits wide.
  98.  
  99. -------------------------------------------------------------------
  100.  
  101. NOTE
  102.     any pointers passe to the following 4 macros are
  103.     guranteed to be 32-bit aligned.
  104.     The only non-32-bit-aligned references ever made are
  105.     to font glyphs, and those are made with getleftbits()
  106.     and getshiftedleftbits (qq.v.)
  107.  
  108. getbits(psrc, x, w, dst)
  109.     starting at position x in psrc (x < 32), collect w
  110.     bits and put them in the screen left portion of dst.
  111.     psrc is a longword pointer.  this may span longword boundaries.
  112.     it special-cases fetching all w bits from one longword.
  113.  
  114.     +--------+--------+        +--------+
  115.     |    | m |n|      |    ==>     | m |n|  |
  116.     +--------+--------+        +--------+
  117.         x      x+w            0     w
  118.     psrc     psrc+1            dst
  119.             m = 32 - x
  120.             n = w - m
  121.  
  122.     implementation:
  123.     get m bits, move to screen-left of dst, zeroing rest of dst;
  124.     get n bits from next word, move screen-right by m, zeroing
  125.          lower m bits of word.
  126.     OR the two things together.
  127.  
  128. putbits(src, x, w, pdst)
  129.     starting at position x in pdst, put down the screen-leftmost
  130.     w bits of src.  pdst is a longword pointer.  this may
  131.     span longword boundaries.
  132.     it special-cases putting all w bits into the same longword.
  133.  
  134.     +--------+            +--------+--------+
  135.     | m |n|  |        ==>    |    | m |n|      |
  136.     +--------+            +--------+--------+
  137.     0     w                     x     x+w
  138.     dst                pdst     pdst+1
  139.             m = 32 - x
  140.             n = w - m
  141.  
  142.     implementation:
  143.     get m bits, shift screen-right by x, zero screen-leftmost x
  144.         bits; zero rightmost m bits of *pdst and OR in stuff
  145.         from before the semicolon.
  146.     shift src screen-left by m, zero bits n-32;
  147.         zero leftmost n bits of *(pdst+1) and OR in the
  148.         stuff from before the semicolon.
  149.  
  150. putbitsrop(src, x, w, pdst, ROP)
  151.     like putbits but calls DoRop with the rasterop ROP (see mfb.h for
  152.     DoRop)
  153.  
  154. putbitsrrop(src, x, w, pdst, ROP)
  155.     like putbits but calls DoRRop with the reduced rasterop ROP
  156.     (see mfb.h for DoRRop)
  157.  
  158. -----------------------------------------------------------------------
  159.     The two macros below are used only for getting bits from glyphs
  160. in fonts, and glyphs in fonts are gotten only with the following two
  161. mcros.
  162.     You should tune these macros toyour font format and cpu
  163. byte ordering.
  164.  
  165. NOTE
  166. getleftbits(psrc, w, dst)
  167.     get the leftmost w (w<=32) bits from *psrc and put them
  168.     in dst.  this is used by the mfbGlyphBlt code for glyphs
  169.     <=32 bits wide.
  170.     psrc is declared (unsigned char *)
  171.  
  172.     psrc is NOT guaranteed to be 32-bit aligned.  on  many
  173.     machines this will cause problems, so there are several
  174.     versions of this macro.
  175.  
  176.     this macro is called ONLY for getting bits from font glyphs,
  177.     and depends on the server-natural font padding.
  178.  
  179.     for blazing text performance, you want this macro
  180.     to touch memory as infrequently as possible (e.g.
  181.     fetch longwords) and as efficiently as possible
  182.     (e.g. don't fetch misaligned longwords)
  183.  
  184. getshiftedleftbits(psrc, offset, w, dst)
  185.     used by the font code; like getleftbits, but shifts the
  186.     bits SCRLEFT by offset.
  187.     this is implemented portably, calling getleftbits()
  188.     and SCRLEFT().
  189.     psrc is declared (unsigned char *).
  190. */
  191.  
  192. #if (BITMAP_BIT_ORDER == IMAGE_BYTE_ORDER)
  193. #define LONG2CHARS(x) (x)
  194. #else
  195. /*
  196.  *  the unsigned case below is for compilers like
  197.  *  the Danbury C and i386cc
  198.  */
  199. #define LONG2CHARS( x ) ( ( ( ( x ) & 0x000000FF ) << 0x18 ) \
  200.                       | ( ( ( x ) & 0x0000FF00 ) << 0x08 ) \
  201.                       | ( ( ( x ) & 0x00FF0000 ) >> 0x08 ) \
  202.                       | ( ( ( x ) & (unsigned long)0xFF000000 ) >> 0x18 ) )
  203. #endif
  204.  
  205. #ifdef STRICT_ANSI_SHIFT
  206. #define SHL(x,y)    ((y) >= 32 ? 0 : LONG2CHARS(LONG2CHARS(x) << (y)))
  207. #define SHR(x,y)    ((y) >= 32 ? 0 : LONG2CHARS(LONG2CHARS(x) >> (y)))
  208. #else
  209. #define SHL(x,y)    LONG2CHARS(LONG2CHARS(x) << (y))
  210. #define SHR(x,y)    LONG2CHARS(LONG2CHARS(x) >> (y))
  211. #endif
  212.  
  213. #if (BITMAP_BIT_ORDER == MSBFirst)    /* pc/rt, 680x0 */
  214. #define SCRLEFT(lw, n)    SHL((unsigned int)(lw),(n))
  215. #define SCRRIGHT(lw, n)    SHR((unsigned int)(lw),(n))
  216. #else                    /* vax, intel */
  217. #define SCRLEFT(lw, n)    SHR((lw),(n))
  218. #define SCRRIGHT(lw, n)    SHL((lw),(n))
  219. #endif
  220.  
  221. #define maskbits(x, w, startmask, endmask, nlw) \
  222.     startmask = starttab[(x)&0x1f]; \
  223.     endmask = endtab[((x)+(w)) & 0x1f]; \
  224.     if (startmask) \
  225.     nlw = (((w) - (32 - ((x)&0x1f))) >> 5); \
  226.     else \
  227.     nlw = (w) >> 5;
  228.  
  229. #define maskpartialbits(x, w, mask) \
  230.     mask = partmasks[(x)&0x1f][(w)&0x1f];
  231.  
  232. #define mask32bits(x, w, startmask, endmask) \
  233.     startmask = starttab[(x)&0x1f]; \
  234.     endmask = endtab[((x)+(w)) & 0x1f];
  235.  
  236. #ifdef __GNUC__
  237. #ifdef vax
  238. #define FASTGETBITS(psrc,x,w,dst) \
  239.     asm ("extzv %1,%2,%3,%0" \
  240.      : "=g" (dst) \
  241.      : "g" (x), "g" (w), "m" (*(char *)(psrc)))
  242. #define getbits(psrc,x,w,dst) FASTGETBITS(psrc,x,w,dst)
  243.  
  244. #define FASTPUTBITS(src, x, w, pdst) \
  245.     asm ("insv %3,%1,%2,%0" \
  246.      : "=m" (*(char *)(pdst)) \
  247.      : "g" (x), "g" (w), "g" (src))
  248. #define putbits(src, x, w, pdst) FASTPUTBITS(src, x, w, pdst)
  249. #endif /* vax */
  250. #ifdef mc68020
  251. #define FASTGETBITS(psrc, x, w, dst) \
  252.     asm ("bfextu %3{%1:%2},%0" \
  253.     : "=d" (dst) : "di" (x), "di" (w), "o" (*(char *)(psrc)))
  254.  
  255. #define getbits(psrc,x,w,dst) \
  256. { \
  257.     FASTGETBITS(psrc, x, w, dst);\
  258.     dst = SHL(dst,(32-(w))); \
  259. }
  260.  
  261. #define FASTPUTBITS(src, x, w, pdst) \
  262.     asm ("bfins %3,%0{%1:%2}" \
  263.      : "=o" (*(char *)(pdst)) \
  264.      : "di" (x), "di" (w), "d" (src), "0" (*(char *) (pdst)))
  265.  
  266. #define putbits(src, x, w, pdst) FASTPUTBITS(SHR((src),32-(w)), x, w, pdst)
  267.  
  268. #endif /* mc68020 */
  269. #endif /* __GNUC__ */
  270.  
  271. /*  The following flag is used to override a bugfix for sun 3/60+CG4 machines,
  272.  */
  273.  
  274. /*  We don't need to be careful about this unless we're dealing with sun3's 
  275.  *  We will default its usage for those who do not know anything, but will
  276.  *  override its effect if the machine doesn't look like a sun3 
  277.  */
  278. #if !defined(mc68020) || !defined(sun)
  279. #define NO_3_60_CG4
  280. #endif
  281.  
  282. /* This is gross.  We want to #define u_putbits as something which can be used
  283.  * in the case of the 3/60+CG4, but if we use /bin/cc or are on another
  284.  * machine type, we want nothing to do with u_putbits.  What a hastle.  Here
  285.  * I used slo_putbits as something which either u_putbits or putbits could be
  286.  * defined as.
  287.  *
  288.  * putbits gets it iff it is not already defined with FASTPUTBITS above.
  289.  * u_putbits gets it if we have FASTPUTBITS (putbits) from above and have not
  290.  *     overridden the NO_3_60_CG4 flag.
  291.  */
  292.  
  293. #define slo_putbits(src, x, w, pdst) \
  294. { \
  295.     register int n = (x)+(w)-32; \
  296.     \
  297.     if (n <= 0) \
  298.     { \
  299.     register int tmpmask; \
  300.     maskpartialbits((x), (w), tmpmask); \
  301.     *(pdst) = (*(pdst) & ~tmpmask) | \
  302.         (SCRRIGHT((unsigned) src, x) & tmpmask); \
  303.     } \
  304.     else \
  305.     { \
  306.     *(pdst) = (*(pdst) & endtab[x]) | (SCRRIGHT((unsigned) (src), x)); \
  307.     (pdst)[1] = ((pdst)[1] & starttab[n]) | \
  308.         (SCRLEFT((unsigned) src, 32-(x)) & endtab[n]); \
  309.     } \
  310. }
  311.  
  312. #if defined(putbits) && !defined(NO_3_60_CG4)
  313. #define u_putbits(src, x, w, pdst) slo_putbits(src, x, w, pdst)
  314. #else
  315. #define u_putbits(src, x, w, pdst) putbits(src, x, w, pdst)
  316. #endif
  317.  
  318. #if !defined(putbits) 
  319. #define putbits(src, x, w, pdst) slo_putbits(src, x, w, pdst)
  320. #endif
  321.  
  322. /* Now if we have not gotten any really good bitfield macros, try some
  323.  * moderately fast macros.  Alas, I don't know how to do asm instructions
  324.  * without gcc.
  325.  */
  326.  
  327. #ifndef getbits
  328. #define getbits(psrc, x, w, dst) \
  329. { \
  330.     dst = SCRLEFT((unsigned) *(psrc), (x)); \
  331.     if ( ((x) + (w)) > 32) \
  332.     dst |= (SCRRIGHT((unsigned) *((psrc)+1), 32-(x))); \
  333. }
  334. #endif
  335.  
  336. /*  We have to special-case putbitsrop because of 3/60+CG4 combos
  337.  */
  338.  
  339. #define u_putbitsrop(src, x, w, pdst, rop) \
  340. {\
  341.     register int t1, t2; \
  342.     register int n = (x)+(w)-32; \
  343.     \
  344.     t1 = SCRRIGHT((src), (x)); \
  345.     DoRop(t2, rop, t1, *(pdst)); \
  346.     \
  347.     if (n <= 0) \
  348.     { \
  349.     register int tmpmask; \
  350.     \
  351.     maskpartialbits((x), (w), tmpmask); \
  352.     *(pdst) = (*(pdst) & ~tmpmask) | (t2 & tmpmask); \
  353.     } \
  354.     else \
  355.     { \
  356.     int m = 32-(x); \
  357.     *(pdst) = (*(pdst) & endtab[x]) | (t2 & starttab[x]); \
  358.     t1 = SCRLEFT((src), m); \
  359.     DoRop(t2, rop, t1, (pdst)[1]); \
  360.     (pdst)[1] = ((pdst)[1] & starttab[n]) | (t2 & endtab[n]); \
  361.     } \
  362. }
  363.  
  364. /* If our getbits and putbits are FAST enough,
  365.  * do this brute force, it's faster
  366.  */
  367.  
  368. #if defined(FASTPUTBITS) && defined(FASTGETBITS) && defined(NO_3_60_CG4)
  369. #if (BITMAP_BIT_ORDER == MSBFirst)
  370. #define putbitsrop(src, x, w, pdst, rop) \
  371. { \
  372.   register int _tmp, _tmp2; \
  373.   FASTGETBITS(pdst, x, w, _tmp); \
  374.   _tmp2 = SCRRIGHT(src, 32-(w)); \
  375.   DoRop(_tmp, rop, _tmp2, _tmp) \
  376.   FASTPUTBITS(_tmp, x, w, pdst); \
  377. }
  378. #define putbitsrrop(src, x, w, pdst, rop) \
  379. { \
  380.   register int _tmp, _tmp2; \
  381.  \
  382.   FASTGETBITS(pdst, x, w, _tmp); \
  383.   _tmp2 = SCRRIGHT(src, 32-(w)); \
  384.   _tmp= DoRRop(rop, _tmp2, _tmp); \
  385.   FASTPUTBITS(_tmp, x, w, pdst); \
  386. }
  387. #undef u_putbitsrop
  388. #else
  389. #define putbitsrop(src, x, w, pdst, rop) \
  390. { \
  391.   register int _tmp; \
  392.   FASTGETBITS(pdst, x, w, _tmp); \
  393.   DoRop(_tmp, rop, src, _tmp) \
  394.   FASTPUTBITS(_tmp, x, w, pdst); \
  395. }
  396. #define putbitsrrop(src, x, w, pdst, rop) \
  397. { \
  398.   register int _tmp; \
  399.  \
  400.   FASTGETBITS(pdst, x, w, _tmp); \
  401.   _tmp= DoRRop(rop, src, _tmp); \
  402.   FASTPUTBITS(_tmp, x, w, pdst); \
  403. }
  404. #undef u_putbitsrop
  405. #endif
  406. #endif
  407.  
  408. #ifndef putbitsrop
  409. #define putbitsrop(src, x, w, pdst, rop)  u_putbitsrop(src, x, w, pdst, rop)
  410. #endif 
  411.  
  412. #ifndef putbitsrrop
  413. #define putbitsrrop(src, x, w, pdst, rop) \
  414. {\
  415.     register int t1, t2; \
  416.     register int n = (x)+(w)-32; \
  417.     \
  418.     t1 = SCRRIGHT((src), (x)); \
  419.     t2 = DoRRop(rop, t1, *(pdst)); \
  420.     \
  421.     if (n <= 0) \
  422.     { \
  423.     register int tmpmask; \
  424.     \
  425.     maskpartialbits((x), (w), tmpmask); \
  426.     *(pdst) = (*(pdst) & ~tmpmask) | (t2 & tmpmask); \
  427.     } \
  428.     else \
  429.     { \
  430.     int m = 32-(x); \
  431.     *(pdst) = (*(pdst) & endtab[x]) | (t2 & starttab[x]); \
  432.     t1 = SCRLEFT((src), m); \
  433.     t2 = DoRRop(rop, t1, (pdst)[1]); \
  434.     (pdst)[1] = ((pdst)[1] & starttab[n]) | (t2 & endtab[n]); \
  435.     } \
  436. }
  437. #endif
  438.  
  439. #if GETLEFTBITS_ALIGNMENT == 1
  440. #define getleftbits(psrc, w, dst)    dst = *((unsigned int *) psrc)
  441. #endif /* GETLEFTBITS_ALIGNMENT == 1 */
  442.  
  443. #if GETLEFTBITS_ALIGNMENT == 2
  444. #define getleftbits(psrc, w, dst) \
  445.     { \
  446.     if ( ((int)(psrc)) & 0x01 ) \
  447.         getbits( ((unsigned int *)(((char *)(psrc))-1)), 8, (w), (dst) ); \
  448.     else \
  449.         getbits(psrc, 0, w, dst);
  450.     }
  451. #endif /* GETLEFTBITS_ALIGNMENT == 2 */
  452.  
  453. #if GETLEFTBITS_ALIGNMENT == 4
  454. #define getleftbits(psrc, w, dst) \
  455.     { \
  456.     int off, off_b; \
  457.     off_b = (off = ( ((int)(psrc)) & 0x03)) << 3; \
  458.     getbits( \
  459.         (unsigned int *)( ((char *)(psrc)) - off), \
  460.         (off_b), (w), (dst) \
  461.            ); \
  462.     }
  463. #endif /* GETLEFTBITS_ALIGNMENT == 4 */
  464.  
  465.  
  466. #define getshiftedleftbits(psrc, offset, w, dst) \
  467.     getleftbits((psrc), (w), (dst)); \
  468.     dst = SCRLEFT((dst), (offset));
  469.  
  470. /* FASTGETBITS and FASTPUTBITS are not necessarily correct implementations of
  471.  * getbits and putbits, but they work if used together.
  472.  *
  473.  * On a MSBFirst machine, a cpu bitfield extract instruction (like bfextu)
  474.  * could normally assign its result to a long word register in the screen
  475.  * right position.  This saves canceling register shifts by not fighting the
  476.  * natural cpu byte order.
  477.  *
  478.  * Unfortunately, these fail on a 3/60+CG4 and cannot be used unmodified. Sigh.
  479.  */
  480. #if defined(FASTGETBITS) && defined(FASTPUTBITS)
  481. #ifdef NO_3_60_CG4
  482. #define u_FASTPUT(aa, bb, cc, dd)  FASTPUTBITS(aa, bb, cc, dd)
  483. #else
  484. #define u_FASTPUT(aa, bb, cc, dd)  u_putbits(SCRLEFT(aa, 32-(cc)), bb, cc, dd)
  485. #endif
  486.  
  487. #define getandputbits(psrc, srcbit, dstbit, width, pdst) \
  488. { \
  489.     register unsigned int _tmpbits; \
  490.     FASTGETBITS(psrc, srcbit, width, _tmpbits); \
  491.     u_FASTPUT(_tmpbits, dstbit, width, pdst); \
  492. }
  493.  
  494. #define getandputrop(psrc, srcbit, dstbit, width, pdst, rop) \
  495. { \
  496.   register unsigned int _tmpsrc, _tmpdst; \
  497.   FASTGETBITS(pdst, dstbit, width, _tmpdst); \
  498.   FASTGETBITS(psrc, srcbit, width, _tmpsrc); \
  499.   DoRop(_tmpdst, rop, _tmpsrc, _tmpdst); \
  500.   u_FASTPUT(_tmpdst, dstbit, width, pdst); \
  501. }
  502.  
  503. #define getandputrrop(psrc, srcbit, dstbit, width, pdst, rop) \
  504. { \
  505.   register unsigned int _tmpsrc, _tmpdst; \
  506.   FASTGETBITS(pdst, dstbit, width, _tmpdst); \
  507.   FASTGETBITS(psrc, srcbit, width, _tmpsrc); \
  508.   _tmpdst = DoRRop(rop, _tmpsrc, _tmpdst); \
  509.   u_FASTPUT(_tmpdst, dstbit, width, pdst); \
  510. }
  511.  
  512. #define getandputbits0(psrc, srcbit, width, pdst) \
  513.     getandputbits(psrc, srcbit, 0, width, pdst)
  514.  
  515. #define getandputrop0(psrc, srcbit, width, pdst, rop) \
  516.         getandputrop(psrc, srcbit, 0, width, pdst, rop)
  517.  
  518. #define getandputrrop0(psrc, srcbit, width, pdst, rop) \
  519.         getandputrrop(psrc, srcbit, 0, width, pdst, rop)
  520.  
  521.  
  522. #else /* Slow poke */
  523.  
  524. /* pairs of getbits/putbits happen frequently. Some of the code can
  525.  * be shared or avoided in a few specific instances.  It gets us a
  526.  * small advantage, so we do it.  The getandput...0 macros are the only ones
  527.  * which speed things here.  The others are here for compatibility w/the above
  528.  * FAST ones
  529.  */
  530.  
  531. #define getandputbits(psrc, srcbit, dstbit, width, pdst) \
  532. { \
  533.     register unsigned int _tmpbits; \
  534.     getbits(psrc, srcbit, width, _tmpbits); \
  535.     putbits(_tmpbits, dstbit, width, pdst); \
  536. }
  537.  
  538. #define getandputrop(psrc, srcbit, dstbit, width, pdst, rop) \
  539. { \
  540.     register unsigned int _tmpbits; \
  541.     getbits(psrc, srcbit, width, _tmpbits) \
  542.     putbitsrop(_tmpbits, dstbit, width, pdst, rop) \
  543. }
  544.  
  545. #define getandputrrop(psrc, srcbit, dstbit, width, pdst, rop) \
  546. { \
  547.     register unsigned int _tmpbits; \
  548.     getbits(psrc, srcbit, width, _tmpbits) \
  549.     putbitsrrop(_tmpbits, dstbit, width, pdst, rop) \
  550. }
  551.  
  552.  
  553. #define getandputbits0(psrc, sbindex, width, pdst) \
  554. {            /* unroll the whole damn thing to see how it * behaves */ \
  555.     register int          _flag = 32 - (sbindex); \
  556.     register unsigned int _src; \
  557.  \
  558.     _src = SCRLEFT (*(psrc), (sbindex)); \
  559.     if ((width) > _flag) \
  560.     _src |=  SCRRIGHT (*((psrc) + 1), _flag); \
  561.  \
  562.     *(pdst) = (*(pdst) & starttab[(width)]) | (_src & endtab[(width)]); \
  563. }
  564.  
  565.  
  566. #define getandputrop0(psrc, sbindex, width, pdst, rop) \
  567. {            \
  568.     register int          _flag = 32 - (sbindex); \
  569.     register unsigned int _src; \
  570.  \
  571.     _src = SCRLEFT (*(psrc), (sbindex)); \
  572.     if ((width) > _flag) \
  573.     _src |=  SCRRIGHT (*((psrc) + 1), _flag); \
  574.     DoRop(_src, rop, _src, *(pdst)); \
  575.  \
  576.     *(pdst) = (*(pdst) & starttab[(width)]) | (_src & endtab[(width)]); \
  577. }
  578.  
  579. #define getandputrrop0(psrc, sbindex, width, pdst, rop) \
  580. { \
  581.     int             _flag = 32 - (sbindex); \
  582.     register unsigned int _src; \
  583.  \
  584.     _src = SCRLEFT (*(psrc), (sbindex)); \
  585.     if ((width) > _flag) \
  586.     _src |=  SCRRIGHT (*((psrc) + 1), _flag); \
  587.     _src = DoRRop(rop, _src, *(pdst)); \
  588.  \
  589.     *(pdst) = (*(pdst) & starttab[(width)]) | (_src & endtab[(width)]); \
  590. }
  591.  
  592. #endif  /* FASTGETBITS && FASTPUTBITS */
  593.